import { Injectable } from '@angular/core';
import { BsModalService } from 'ngx-bootstrap/modal';
import { BsModalRef } from 'ngx-bootstrap/modal/modal-options.class';
import { ModalConfirmComponent } from './modal-confirm.component';
import { IModalConfirmOptions } from './modal-confirm.types';

@Injectable()
export class ModalConfirmService {
  constructor(private modalService: BsModalService) {}

  open({ content, onOk, config }: IModalConfirmOptions) {
    const modalRef: BsModalRef = this.modalService.show(ModalConfirmComponent, config);
    modalRef.content.content = content;
    // ok button
    modalRef.content.onOk = () => {
      if (onOk) {
        onOk();
      }
    };
  }
}
